package cn.howxu.yichen_ovo.common.item;

import cn.howxu.yichen_ovo.registry.DollRegistryEvent;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class DollItem extends BlockItem {
    public final ArrayList<String> Tips;
    private final int Level;
    private final Block block;

    public DollItem(Block block, String[] tips,int level) {
        super(block, switch (level){
            case 1 -> new Properties().rarity(Rarity.UNCOMMON);
            case 2 -> new Properties().rarity(Rarity.RARE);
            case 3 -> new Properties().rarity(Rarity.EPIC);
            default -> new Properties().rarity(Rarity.COMMON);
        });
        this.Tips = new ArrayList<>(List.of(tips));
        this.Level = level;
        this.block = block;
        for (int i = 0; i < Tips.size(); i++) {
            Tips.set(i, "tooltip.yichenovo.doll." + ForgeRegistries.BLOCKS.getKey(block).getPath() + "." + Tips.get(i));
        }
        DollRegistryEvent.Jade_Plugin_tips.put(ForgeRegistries.BLOCKS.getKey(block).getPath(),Tips);
        DollRegistryEvent.Jade_Plugin_levels.put(ForgeRegistries.BLOCKS.getKey(block).getPath(), level);
    }

    @Override
    public EquipmentSlot getEquipmentSlot(ItemStack stack) {
        return EquipmentSlot.HEAD;
    }

    @Override
    public Component getName(ItemStack stack) {
        return Component.translatable("block.yichen_ovo.doll." + ForgeRegistries.BLOCKS.getKey(block).getPath());
    }

    @Override
    public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> list, TooltipFlag flag) {
        final ChatFormatting formatting;
        switch (this.Level){
            case 1 -> {
                formatting = ChatFormatting.GREEN;
            }
            case 2 -> {
                formatting = ChatFormatting.LIGHT_PURPLE;
            }
            case 3 -> {
                formatting = ChatFormatting.RED;
            }
            default -> {
                formatting = ChatFormatting.WHITE;
            }
        }
        Tips.forEach(s -> {
            list.add(Component.translatable(s).withStyle(formatting));
        });
        
    }
}
